<script setup lang="ts">
import { ref, onMounted } from 'vue'
import DoctorCard from './DoctorCard.vue'
// import { useWindowWidth } from '@/composable'
import { useWindowSize } from '@vueuse/core'
import type { DoctorList } from '@/types/consult'
import { getDoctorPage } from '@/services/consult'

// 组一下 hook一下
// const { width } = useWindowWidth() // width响应式的 跟随屏幕自动跟新大小
const { width } = useWindowSize()

const list = ref<DoctorList>([])
const loadData = async () => {
  const res = await getDoctorPage({
    current: 1,
    pageSize: 10
  })

  list.value = res.data.rows
}

onMounted(() => {
  loadData()
})
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件: 本身是一屏一屏的滑动 不合理的 默认是以一屏的宽度滑动 -->
      <!-- 这边手机先用375屏!!! -->
      <!-- 
        我们150 是card的宽度+左外边距   任意屏幕下都是150  写死了
        屏幕将来是会变大 变小的  150不能继续写死了

        解决: 375屏幕下 150;   414屏幕下   x= (150/375) * 当前屏幕的宽度     150/375 = x/414
       -->
      <van-swipe
        :width="(150 / 375) * width"
        :show-indicators="false"
        :loop="false"
      >
        <van-swipe-item v-for="item in list" :key="item.id">
          <DoctorCard :item="item"></DoctorCard>
        </van-swipe-item>
      </van-swipe>

      <!-- v-for 遍历数字 -->
      <!-- <DoctorCard v-for="item in 10" :key="item"></DoctorCard> -->
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>
